# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=setuptools
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=47.1.1
pkgrel=1
pkgdesc="Easily download, build, install, upgrade, and uninstall Python packages"
arch=('any')
license=('PSF')
url="https://pypi.python.org/pypi/setuptools"
depends=('python')
provides=("python3-${_realname}" 'python3-distribute')
replaces=("python3-${_realname}" 'python3-distribute')
conflicts=("python3-${_realname}")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/pypa/setuptools/archive/v${pkgver}.tar.gz")
sha512sums=('fad8a81f4f5650248f56f4f656957f047caed724e696507d602246fbc002ff893776fef41b7861197e20210dbbc4f076558679dce0c37e5860fb3d4bcc1be130')

prepare() {
  # Don't download and install deps
  sed -i '/pip.main(args)/d' setuptools-${pkgver}/bootstrap.py

  # Remove post-release tag since we are using stable tags
  sed -e '/tag_build = .post/d' \
      -e '/tag_date = 1/d' \
      -i setuptools-${pkgver}/setup.cfg

  cd "${srcdir}"/setuptools-${pkgver}
  sed -i -e "s|^#\!.*/usr/bin/env python|#!/usr/bin/env python3|" setuptools/command/easy_install.py

  export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0
}

build() {
  # Build python module
  cd "${srcdir}"/setuptools-${pkgver}
  /usr/bin/python bootstrap.py
  /usr/bin/python setup.py build
}

check() { (
  # Workaround UTF-8 tests by setting LC_CTYPE
  export LC_CTYPE=en_US.UTF-8

  # https://github.com/pypa/setuptools/pull/810
  export PYTHONDONTWRITEBYTECODE=1

  # Check python module
  # cd "${srcdir}"/setuptools-${pkgver}
  # /usr/bin/python setup.py pytest
)}

package() {
  cd "${srcdir}"/setuptools-${pkgver}

  /usr/bin/python setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 --skip-build
}
